import { Component, OnInit } from '@angular/core';
import {Hero} from '../../model/hero'

import { HeroService } from './../../services/hero.service';
import { MessageService } from './../../services/message.service';

@Component({
  selector: 'app-heros',
  templateUrl: './heros.component.html',
  styleUrls: ['./heros.component.scss']
})
export class HerosComponent implements OnInit {
  heros:Hero[] = []
  selectedHero?: Hero;
  constructor(
    private heroService: HeroService,
    private messageService: MessageService
  ) { }

  ngOnInit(): void {
    this.getHeroes()
  }
  onSelect(hero:Hero): void {
    this.messageService.add('hero selcted:name=' + hero.name)
    this.selectedHero = hero
  }
  getHeroes(): void {
    this.heroService.getHeroes().subscribe(heroes => this.heros = heroes);
  }
}
